<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>剩余参数</title>
</head>

<body>
    <script>
        // 利用剩余参数求和
        function getSum(a, b, ...other) {
            let sum = a + b;
            for (let i = 0; i < other.length; i++) {
                sum += other[i]
            }
            console.log(sum);
        }
        getSum(1, 2, 3) // 6
        getSum(1, 2, 3, 4) // 10
    </script>
</body>

</html>